<template>
  <div class="box">
    <el-form ref="form" :model="form" label-width="80px" style="width: 100%;margin-top: 30px;">
      <el-form-item label="原始密码">
        <el-input v-model="form.oldpassword" type="password"></el-input>
      </el-form-item>
      <el-form-item label="新密码">
        <el-input v-model="form.newpassword" type="password"></el-input>
      </el-form-item>
      <el-form-item label="重复密码">
        <el-input v-model="form.newspassword" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" size="small">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import qs from "qs"
import store from '@/vuex/store'
export default {
  name: 'App',
  data(){
    return{
      form: {
        oldpassword: '',
        newpassword: '',
        newspassword: ''
      }
    }
  },
  methods:{
    onSubmit:function(){
      console.log(this.form)
      if(this.form.newpassword != this.form.newspassword){
        alert('新密码与重复密码必须一致')
      }else{
          this.$http.post("/index.php/user/user/updatepwd",qs.stringify({
                // mobile:this.tel,
                // password:this.pwd
                    user_id: this.$store.state.userid,
                    password: this.form.newpassword,
                    repassword: this.form.newspassword
                }))
                .then(res => {
                  if(res.data.code==-1){
                    this.$message({
                      type: 'error',
                      message: '原始密码不正确，修改密码失败！'
                    });
                  }else{
                    this.$message({
                      type: 'success',
                      message: '修改成功!'
                    });
                  }
                  
                })
                .catch(error => {
                  alert("网络错误")
                });
      }
    }
  },
  components:{
    
  }
}
</script>

<style scoped lang="less">
.box{
  padding: 0 .2rem;
  height: 300px;
  border-top: .2rem solid #d5d5d5;
}
</style>
